require("func")

math.randomseed(os.time())

local width = 20
local height = 20

local astar = require("AStar"):create(width, height)
for i = 1, width do
	for j = 1, height do
		astar:setGridCanMove({x = j, y = i}, math.random(10) < 8)
	end
end

astar:setGridCanMove({x = 1, y = 1}, true)
astar:setGridCanMove({x = width, y = height}, true)

-- 输出地图
astar:debug()

-- -- 查找最优路径
-- local path = {}
-- astar:findOptimumSolution(path, {x = 1, y = 1}, {x = width, y = height})

-- astar:debug(path, {x = 1, y = 1}, {x = width, y = height})

-- 查找不可以斜着走的最优路径
astar:setCanOblique(false)
path = {}
astar:findOptimumSolution(path, {x = 1, y = 1}, {x = width, y = height})
astar:debug(path, {x = 1, y = 1}, {x = width, y = height})

astar:setCanOblique(false)
path = {}
astar:findOptimumSolution(path, {x = width, y = height}, {x = 1, y = 1})
astar:debug(path, {x = width, y = height}, {x = 1, y = 1})


